package com.freedom.clue.verifyHandler;

import cn.afterturn.easypoi.excel.entity.result.ExcelVerifyHandlerResult;
import cn.afterturn.easypoi.handler.inter.IExcelVerifyHandler;
import com.freedom.auth.vo.ClueImportVo;
import com.freedom.clue.domain.Clue;
import com.freedom.clue.service.IClueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author freedom
 */
@Component
public class ClueVerifyHandler implements IExcelVerifyHandler<ClueImportVo> {
    @Autowired
    private IClueService clueService;


    @Override
    public ExcelVerifyHandlerResult verifyHandler ( ClueImportVo vo ) {
        ExcelVerifyHandlerResult result = new ExcelVerifyHandlerResult();
        String name = vo.getName();

        // 比对数据库是否有这个线索客户
        Clue clue = clueService.getByName(name);

        if (clue != null) {
            // 校验失败
            result.setMsg("唯一校验失败");
            result.setSuccess(false);
            return result;
        }
        result.setSuccess(true);
        return result;
    }
}
